package com.jianan.mis.service;

import java.io.Serializable;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.jianan.mis.data.dao.OsDepartmentContractDao;
import com.jianan.mis.data.dao.base.PageControl;
import com.jianan.mis.data.domain.OsDepartmentContract;

public class OsDepartmentContractServiceImpl implements OsDepartmentContractService {

	private OsDepartmentContractDao osDepartmentContractDao;

	public Serializable save(OsDepartmentContract osDepartmentContract) {
		return osDepartmentContractDao.save(osDepartmentContract);
	}
	
	public void pageQuery(PageControl pageControl, Map conditions) {
		Criteria criteria = osDepartmentContractDao.createCriteria(OsDepartmentContract.class);
		if (conditions.get("studentName") != null) {
			String studentName = (String) conditions.get("studentName");
			criteria.add(Restrictions.like("Name", studentName, MatchMode.ANYWHERE));
		}
		if (conditions.get("countryId") != null) {
			Integer countryId = (Integer) conditions.get("countryId");
			criteria.add(Expression.eq("Country.id", countryId));
		}
		if (conditions.get("contractNo") != null) {
			String contractNo = (String) conditions.get("contractNo");
			criteria.add(Restrictions.like("ContractNo", contractNo, MatchMode.ANYWHERE));
		}
		if (conditions.get("departmentId") != null) {
			Integer departmentId = (Integer) conditions.get("departmentId");
			criteria.add(Expression.eq("Department.id", departmentId));
		}
		criteria.addOrder(Order.asc("id"));
		pageControl = osDepartmentContractDao.pagedQuery(criteria, pageControl);
	}
	public boolean checkContractNoExists(String contractNo) {
		if (osDepartmentContractDao.findUniqueBy(OsDepartmentContract.class, "ContractNo",
				contractNo) != null)
			return true;
		else
			return false;
	}

	public void setOsDepartmentContractDao(
			OsDepartmentContractDao osDepartmentContractDao) {
		this.osDepartmentContractDao = osDepartmentContractDao;
	}

}
